package com.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import javax.annotation.Resource;
import java.io.IOException;


// 实现运行配置好的数据库驱动文件
public class MapperUtil {
//静态修饰获取数据配置驱动文件
//    获取sql配置数据库文件
    public static final SqlSessionFactory sqlSession_sql=geSqlSessionFactory("poi-config-mapper-sql.xml");
//    获取sqlite配置文件驱动
    public static final SqlSessionFactory sqlSession_sqlite=geSqlSessionFactory("poi-config-mapper-sqlite.xml");


    //以下为具体获取Session配置文件的方法
    private static SqlSessionFactory geSqlSessionFactory(String configFile){
       //初始化
        SqlSessionFactory sqlSessionFactory = null;
        try{
            sqlSessionFactory =new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream(configFile));
        }catch (IOException e){
            e.printStackTrace();
        }
        return sqlSessionFactory;
    }
}
